package com.xzlf;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ResourceMgr {

    public static ExecutorService pool = Executors.newFixedThreadPool(10);
    ;
    public static BufferedImage tankU, tankD, tankL, tankR;
    public static BufferedImage badTankU, badTankD, badTankL, badTankR;
    public static BufferedImage bulletU, bulletD, bulletL, bulletR;
    public static BufferedImage[] explodes = new BufferedImage[16];
    public static byte[] bytes = new byte[1024 * 8];
    public static byte[] bytesFire = new byte[1024 * 480];
    public static byte[] bytesMove = new byte[1024 * 32];
    public static byte[] bytesWar1 = new byte[1024 * 1024 * 12];

    static {
        ClassLoader classLoader = ResourceMgr.class.getClassLoader();
        try {
            tankU = ImageIO.read(classLoader.getResourceAsStream("images/GoodTank1.png"));
            tankD = ImageUtil.rotateImage(tankU, 180);
            tankL = ImageUtil.rotateImage(tankU, -90);
            tankR = ImageUtil.rotateImage(tankU, 90);

            badTankU = ImageIO.read(classLoader.getResourceAsStream("images/BadTank1.png"));
            badTankL = ImageUtil.rotateImage(badTankU, -90);
            badTankR = ImageUtil.rotateImage(badTankU, 90);
            badTankD = ImageUtil.rotateImage(badTankU, 180);

            bulletU = ImageIO.read(classLoader.getResourceAsStream("images/bulletU.gif"));
            bulletL = ImageUtil.rotateImage(bulletU, -90);
            bulletR = ImageUtil.rotateImage(bulletU, 90);
            bulletD = ImageUtil.rotateImage(bulletU, 180);

            for (int i = 0; i < 16; i++) {
                explodes[i] = ImageIO.read(classLoader.getResourceAsStream("images/e" + (i + 1) + ".gif"));
            }
            BufferedInputStream inputStream = new BufferedInputStream(
                    classLoader.getResourceAsStream("audio/explode.wav")
            );
            inputStream.read(bytes);
            BufferedInputStream isfire = new BufferedInputStream(
                    classLoader.getResourceAsStream("audio/tank_fire.wav")
            );
            isfire.read(bytesFire);
            BufferedInputStream isMove = new BufferedInputStream(
                    classLoader.getResourceAsStream("audio/tank_move.wav")
            );
            isMove.read(bytesMove);
            BufferedInputStream isWar = new BufferedInputStream(
                    classLoader.getResourceAsStream("audio/war1.wav")
            );
            isWar.read(bytesWar1);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
